package com.woniuxy.stage3demo.service.otherPzc.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.otherPzc.QainforBean;
import com.woniuxy.stage3demo.mapper.otherPzc.QainforMapper;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.service.otherPzc.IQainforService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class QainforServiceImpl implements IQainforService {

    @Autowired
    private QainforMapper qainforMapper;

    /**
     * 新增帮助信息
     *
     * @param qainforBean 新增的帮助信息对象
     * @return 数据库操作的行数
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int saveQainfor(QainforBean qainforBean) {
        return qainforMapper.saveQainfor(qainforBean);
    }

    /**
     * 删除帮助信息
     *
     * @param id 删除的帮助信息对象的id
     * @return 数据库操作的行数
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int deleteQainfor(int id) {
        return qainforMapper.deleteQainfor(id);
    }

    /**
     * 修改帮助信息
     *
     * @param qainforBean 修改的帮助信息对象
     * @return 操作行数
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updateQainfor(QainforBean qainforBean) {
        return qainforMapper.updateQainfor(qainforBean);
    }

    /**
     * 分页查询
     *
     * @param request
     * @param qainforBean
     * @return
     */
    @Override
    public PageInfo<QainforBean> findAllByParams(PageRequest request, QainforBean qainforBean) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->qainforMapper.findAllByParams(request,qainforBean));
    }
}
